package com.lyy.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.lyy.system.dao.SysDictDao;
import com.lyy.system.pojo.SysDict;
import com.lyy.system.service.SysDictService;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.lyy.common.utils.UUIDUtils;

import java.util.List;
import java.util.Date;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;

/**
 * 字典表(SysDict)表服务实现类
 *
 * @author Yw
 * @since 2021-02-01 17:19:49
 */
@Service
public class SysDictServiceImpl extends ServiceImpl<SysDictDao, SysDict> implements SysDictService {


    /**
     * 添加字典表
     *
     * @param sysDict
     */
    @Override
    public void createSysDict(SysDict sysDict) {
        sysDict.setDelFlag("0");
        baseMapper.insert(sysDict);
    }

    /**
     * 根据主键修改字典表
     *
     * @param sysDict
     */
    @Override
    public void updateSysDict(SysDict sysDict) {
        baseMapper.update(sysDict, new UpdateWrapper<SysDict>()
                .eq("id", sysDict.getId())
        );
    }

    /**
     * 根据主键删除字典表
     *
     * @param id 字典id
     * @return
     */
    @Override
    public void deleteSysDict(SysDict sysDict) {
        baseMapper.delete(new UpdateWrapper<SysDict>()
                .eq("id", sysDict.getId())
        );
    }

    /**
     * 根据主键查询字典表详情
     *
     * @param id 字典id
     * @return
     */
    @Override
    public SysDict getSysDict(SysDict sysDict) {
        return baseMapper.selectOne(new QueryWrapper<SysDict>()
                .eq("id", sysDict.getId())
        );
    }

    /**
     * 批量添加字典表
     *
     * @param sysDicts
     */
    @Override
    public int batchInsert(List<SysDict> sysDicts) {
        return baseMapper.batchInsert(sysDicts);
    }


    /**
     * 批量修改字典表
     *
     * @param sysDicts
     */
    @Override
    public int batchUpdate(List<SysDict> sysDicts) {
        return baseMapper.batchUpdate(sysDicts);
    }

    /**
     * 查询字典表列表
     *
     * @param sysDict
     */
    @Override
    public List<SysDict> selectSysDictList(SysDict sysDict) {
        return baseMapper.selectSysDictList(sysDict);
    }

    /**
     * 查询字典表数量
     *
     * @param sysDict
     */
    @Override
    public int selectSysDictCount(SysDict sysDict) {
        return baseMapper.selectSysDictCount(sysDict);
    }


    /**
     * 导入字典表excel
     *
     * @param sysDicts
     */
    @Override
    public List<Map<String, String>> importSysDictExcel(List<SysDict> sysDicts) {
        List<Map<String, String>> mapList = new ArrayList<>();
        sysDicts.forEach(sysDict -> {
            sysDict.setId(UUIDUtils.getUUIDTWO());
            Map<String, String> map = new HashMap<>();
            map.put("status", "0");
            map.put("reason", "导入成功");
            mapList.add(map);
        });
        batchInsert(sysDicts);
        return mapList;
    }
}